package com.ruoyi.livedemo.mapper;

import com.ruoyi.livedemo.entity.PartnerEvaluation;
import org.apache.ibatis.annotations.*;

@Mapper
public interface PartnerEvaluationMapper {

    @Select("SELECT * FROM partner_evaluations WHERE user_id=#{userId} " +
            "ORDER BY updated_at DESC, id DESC LIMIT 1")
    PartnerEvaluation findLatestByUser(Long userId);

    @Insert("INSERT INTO partner_evaluations (user_id, partner_name, strengths, improvements, appreciation) " +
            "VALUES (#{userId}, #{partnerName}, #{strengths}, #{improvements}, #{appreciation})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(PartnerEvaluation evaluation);

    @Update("UPDATE partner_evaluations SET partner_name=#{partnerName}, strengths=#{strengths}, " +
            "improvements=#{improvements}, appreciation=#{appreciation}, updated_at=NOW() " +
            "WHERE id=#{id} AND user_id=#{userId}")
    int update(PartnerEvaluation evaluation);
}

